﻿using MCUPackage;
using MCUPackage.Utils;
using System;
using System.ComponentModel;

namespace SxPackages.STC32G.Models
{
	[Serializable]
	class UART4Options : USARTOptionBase
	{
		private UART4Pins mPins = UART4Pins.RxD_P02_TxD_P03;
		[DisplayName("使用引脚"),
		DefaultValue(UART4Pins.RxD_P02_TxD_P03),
		Description("本串口使用的引脚设置")]
		public UART4Pins Pins
		{
			get => mPins;
			set
			{
				if (value != mPins)
				{
					if (SwitchPins(value, mPins))
					{
						mPins = value;
					}
				}
			}
		}

		protected override void SetPins(String[] aPins)
		{
			var opt = mParent.SetPinPurpose(aPins[0], PinPurpose.UART4_RCV);
			opt.Mode = GPIOMode.Standard;
			opt.Speed = GPIOSpeed.Fast;
			opt.EnableUp = true;
			opt = mParent.SetPinPurpose(aPins[1], PinPurpose.UART4_SND);
			opt.Mode = GPIOMode.Push;
			opt.Speed = GPIOSpeed.Fast;
		}

		public UART4Options(STC32GQFP64 aParent) : base(aParent)
		{
			Id = 4;
			mUsePins = TemplateHelper.GetPins(mPins);
		}
	}
}
